﻿using UnityEngine;

namespace Vosvek.ProjectRogue
{

    /// <summary>
    /// The gathering spot is a spot the user can interact with to gather a 
    /// resource. For example, there are fishing spots, ore deposits, trees, 
    /// and more. Ideally, the actor uses the spot, and the spot evaluates 
    /// whether the user has the requirements (right level, tools, etc.), before
    /// checking whether the user recieves an item or something else.
    /// </summary>
    [RequireComponent(typeof(SpriteRenderer),
                      typeof(Collider2D))]
    public class GatheringSpot : MonoBehaviour, IPlayerUsable
    {
        [SerializeField] string displayName;
        [SerializeField] Sprite AvailableSprite;
        [SerializeField] Sprite DepletedSprite;
        [SerializeField] bool isDepleted;
        [SerializeField] int RegenTurnCooldown;
        // Requirements
        // GatheringResourceTree

        SpriteRenderer spriteRenderer;
        int regenTimer;

        public string DisplayName { get { return displayName; } }
        public bool IsDepleted { get { return isDepleted; } }

        void Start()
        {
            spriteRenderer = GetComponent<SpriteRenderer>();
        }

        void UpdateSprite()
        {
            if (spriteRenderer != null)
            {
                if (isDepleted && DepletedSprite != null)
                {
                    spriteRenderer.sprite = DepletedSprite;
                }
                else if (AvailableSprite != null)
                {
                    spriteRenderer.sprite = AvailableSprite;
                }
            }
        }

        public void OnPlayerUse(Player player)
        {
            // TODO: Implement.
            throw new System.NotImplementedException();
        }

        public void OnTurnTick()
        {
            if (isDepleted)
            {
                if (regenTimer >= RegenTurnCooldown)
                {
                    isDepleted = false;
                    regenTimer = 0;
                }
                else
                {
                    regenTimer++;
                }
            }
        }
    }

}
